Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

249
Views
How to specify "sources" JAR for local JAR dependency?

I have a *.jar file in my Gradle / Buildship project that resides in a lib folder. I include it in my build.gradle via:

compile files('libs/local-lib.jar')

I also have a correspondinglocal-lib-sources.jar file that I would like to attach to it. In Eclipse, for manually managed dependencies this works via context menu of build path entry -> Properties -> Java Source Attachment. However, for gradle-managed dependencies, that option is not available.

Does anybody know how what the gradle/buildship way to do this looks like? My dependency is in no repository, so I'm stuck with compile files for now.

over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

If you want to use Buildship with Eclipse then you are out of luck since this is not currently supported by gradle (see https://discuss.gradle.org/t/add-sources-manually-for-a-dependency-which-lacks-of-them/11456/8).

If you are ok with not using Buildship and manually generating the Eclipse dot files you can do something like this in your build.gradle:

apply plugin: 'eclipse'

eclipse.classpath.file {
  withXml {
    xml ->
    def node = xml.asNode()
    node.classpathentry.forEach {
      if(it.@kind == 'lib') {
        def sourcePath = it.@path.replace('.jar', '-sources.jar')
        if(file(sourcePath).exists()) {
          it.@sourcepath = sourcePath
        }
      }
    }
  }
}

You would then run gradle eclipse from the command line and import the project into Eclipse using Import -> "Existing Projects into Workspace"

Another (possibly better) option would be to use a flat file repository like this:

repositories {
    flatDir { 
        dirs 'lib'
}

see https://docs.gradle.org/current/userguide/dependency_management.html#sec:flat_dir_resolver

You would then just include your dependency like any other; in your case:

compile ':local-lib'

This way Buildship will automatically find the -sources.jar files since flatDir acts like a regular repository for the most part.

over 4 years ago · Santiago Trujillo Report

0

Use an extra folder called lib or similar on the same directory level as src or you build script.

dependencies {
//local file
     compile files('lib/local-lib-sources.jar')
// others local or remote file
 }
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!